﻿using System;
using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
using Microsoft.Practices.EnterpriseLibrary.Validation.Validators;

namespace Metro.Kashikoi.ServiceContract.Storage
{
    /// <summary>
    /// Auto trigger.
    /// </summary>
    [DataContract(IsReference = true)]
    [KnownType(typeof(WeeklyTrigger))]
    [KnownType(typeof(DailyTrigger))]
    [Table("AutoTriggers")]
    public abstract class AutoTrigger : Trigger
    {
        /// <summary>
        /// Gets or sets the start time.
        /// </summary>
        /// <value>
        /// The start.
        /// </value>
        [DataMember]
        [Required]
        [DateTimeRangeValidator("1753-01-01T00:00:00", "9999-12-31T00:00:00")]
        public DateTime Start { get; set; }

        /// <summary>
        /// Gets or sets the end time. If the end is null, there is no end time.
        /// </summary>
        /// <value>
        /// The end.
        /// </value>
        [DataMember]
        [DateTimeRangeValidator("1753-01-01T00:00:00", "9999-12-31T00:00:00")]
        public DateTime? End { get; set; }

        /// <summary>
        /// Gets or sets the frequency.
        /// </summary>
        /// <value>
        /// The frequency.
        /// </value>
        [DataMember]
        [Range(1, int.MaxValue)]
        [RangeValidator(1, RangeBoundaryType.Inclusive, int.MaxValue, RangeBoundaryType.Inclusive)]
        public int Frequency { get; set; }

        /// <summary>
        /// Copies the specified to the destination.
        /// </summary>
        /// <param name="destination">The destination.</param>
        protected void CopyTo(AutoTrigger destination)
        {
            destination.Start = this.Start;
            destination.End = this.End;
            destination.Frequency = this.Frequency;
        }
    }
}
